package leetcode.offer;

/**
 * ClassName: BestStockProfit
 * Description: leetcode-剑指offer 63.股票的最大利润
 * date: 2021-11-03 10:59
 *
 * @author liyifan
 */
public class BestStockProfit {
    public int maxProfit(int prices[]){
        int minPrice = Integer.MAX_VALUE;
        int maxProfit = 0;
        for (int i = 0;i < prices.length;i++) {
            if (prices[i] < minPrice) {
                minPrice = prices[i];
            }
            if (prices[i] - minPrice > maxProfit) {
                maxProfit = prices[i] - minPrice;
            }
        }
        return maxProfit;
    }
}
